#include "gc.h"

typedef struct _innerObj{
	struct _innerObj * in;
}InnerObj;

int main(){
	g_debug = TRUE;
	InnerObj * obj = gc_malloc(sizeof(InnerObj));
	InnerObj * in = gc_malloc(sizeof(InnerObj));
	gc_add_root_node(&obj);
	gc_add_root_node(&in);
	obj->in = in;
	printf("\nTry recycle: can't recycle any node cause they are all reachable!\n");
	gc_recycle();

	printf("\nFree the root node in(ptr = %d) and try recycle again...\n", (int)in);
	printf("You can see that although the root node in(ptr = %d) has been freed,"
			"but no heap nodes actually have been freed, "
			"because the     in(ptr = %d) is still "
			"reachable from obj(ptr = %d)", (int)in, (int)in, (int)obj);
	gc_free_root_node(&in);
	gc_recycle();

	printf("\nFree the root node obj(ptr = %d) and try recycle again...\n", (int)obj);
	printf("You can see now all the root nodes and heap nodes has been freed successfully!\n");
	gc_free_root_node(&obj);
	gc_recycle();

	printf("\nSuccessfully run gc_test_innerref!\n");
}
